<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
       
      <el-form-item label="文件类型" prop="fileType">
        <el-input v-model="queryParams.fileType" />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" show-overflow-tooltip width="50px"/>
      <el-table-column label="操作人员" align="center" prop="creatorId" />
      <el-table-column label="导入文件类型" align="center" prop="fileType" />
      <el-table-column label="项目条数" align="center" prop="projectCount" />
      <el-table-column label="成功条数" align="center" prop="successCount" />
      <el-table-column label="漏填条数" align="center" prop="ldCount"> </el-table-column>
      <el-table-column label="创建人" align="center" prop="creatorId" />
      <el-table-column label="创建时间" align="center" prop="creatorDate" width="180">  </el-table-column>
    
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords, exportRecords } from "@/api/tender/records";

export default {
  name: "Records",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 导入记录表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        fileType: undefined,
        projectCount: undefined,
        successCount: undefined,
        insertCount: undefined,
        ldCount: undefined,
        creatorId: undefined,
        creatorDate: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询导入记录列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        if(response.code==='ok') {
            this.recordsList = response.data.data.list;
            this.total = response.data.data.total;
            this.loading = false;
        }else{
            this.recordsList = [];
            this.total = 0;
            this.loading = false;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        fileType: undefined,
        projectCount: undefined,
        successCount: undefined,
        insertCount: undefined,
        ldCount: undefined,
        creatorId: undefined,
        creatorDate: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加导入记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecords(id).then(response => {
        this.form = response.data.data;
        this.open = true;
        this.title = "修改导入记录";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateRecords(this.form).then(response => {
                if(response.code==='ok') {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.data.msg);
              }
            });
          } else {
            addRecords(this.form).then(response => {
                if(response.code==='ok') {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.data.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除导入记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRecords(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有导入记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRecords(queryParams);
        }).then(response => {
          var blob=response.data.data
          var url = window.URL.createObjectURL(blob);
          var a = document.createElement('a');
          a.href = url;
          a.download =(new Date()).valueOf()+'.xlsx';
          a.click();
          window.URL.revokeObjectURL(url);
        }).catch(function() {});
    }
  }
};
</script>